﻿#pragma once
#pragma execution_character_set("utf-8")
// 本文件为utf-8 编码格式

#ifndef __GD__GDAlertView__
#define __GD__GDAlertView__

#include "CrossApp.h"
#include <iostream>
#include <string>
#include <vector>
#include "../GdDefine.h"

#define GD_ALERT_VIEW_TITLE_FONT 30
#define GD_ALERT_VIEW_MESG_FONT 26
#define GD_ALERT_VIEW_WIDTH 540
#define GD_ALERT_VIEW_MESG_WIDTH 472


class GDAlertView 
	: public CAView
	, public CATableViewDataSource
	, public CATableViewDelegate
{
public:

	GDAlertView();
	virtual ~GDAlertView();

	static GDAlertView *create();

	static GDAlertView *createWithText(const char* pszTitle, const char* pszAlertMsg, const char* pszBtnText, ...);

	bool initWithText(const char* szTitle, const char* szAlertMsg, const char* pszBtnText, ...);

	void addButton(const std::string& btnText, CAColor4B col = GD_COLOR_646464, CAImage* pNormalImage = NULL, CAImage* pHighlightedImage = NULL);

	void addButton(CAButton* pBtn);

	void setTarget(CAObject* target, SEL_CAAlertBtnEvent selector);

	void show(float dt=0);
	void delayShow(float dt=0);

	//optional
	void setMessageFontName(std::string &var);

	void setTitle(std::string var, CAColor4B col = CAColor_black);

	void setAlertMessage(std::string var, CAColor4B col = CAColor_black);

protected:

	bool init();

	virtual CATableViewCell* tableCellAtIndex(CATableView* table, const CCSize& cellSize, unsigned int section, unsigned int row);

	virtual unsigned int numberOfRowsInSection(CATableView *table, unsigned int section);

	virtual unsigned int tableViewHeightForRowAtIndexPath(CATableView* table, unsigned int section, unsigned int row);

	void onClickButton(CAControl* btn, CCPoint point);

	void setLabel(CALabel*& pLabel, const char* szTitle, const char* fontName, const CAColor4B& col, int fontSize = _ds(ALERT_VIEW_MESG_FONT));

private:

	void showAlertView();

	void adjustButtonView();

	void addGrayLine(int y);

	void calcuAlerViewSize();

private:

	std::string m_sMsgFontName;

	CALabel* m_pTitleLabel;

	CALabel* m_pContentLabel;

	CAVector<CAButton*> m_vAllBtn;

	CATableView* m_pBtnTableView;

	SEL_CAAlertBtnEvent m_pCAlertBtnEvent;

	CAObject* m_pCAlertTarget;

	float m_fAlertViewHeight;

	float m_fAlertViewTitleHeight;

	float m_fAlertViewMessageHeight;

	float m_fAlertViewLineHeight;

	CAView *m_pBackView;

	float alertViewButtonHeight;

	bool isDelayShow; // 是否是延时显示
};
#endif /* defined(__HelloCpp__ViewController__) */